package com.ruoyi.web.controller.api;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ApiUserScenicArea;
import com.ruoyi.system.service.IApiUserScenicAreaService;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScenicArea;
import com.ruoyi.system.service.IScenicAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景区信息Controller
 *
 * @author duantao
 * @date 2025-07-02
 */
@RestController
@RequestMapping("/api/scenicArea")
public class ScenicAreaController extends BaseController
{
    @Autowired
    private IScenicAreaService scenicAreaService;

    @Autowired
    private IApiUserScenicAreaService userScenicAreaService;

    /**
     * 查询景区信息列表
     */
//    @PreAuthorize("@ss.hasPermi('api:scenicArea:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScenicArea scenicArea)
    {
        startPage();
        List<ScenicArea> list = scenicAreaService.selectScenicAreaList(scenicArea);
        return getDataTable(list);
    }

    /**
     * 导出景区信息列表
     */
    @PreAuthorize("@ss.hasPermi('api:scenicArea:export')")
    @Log(title = "景区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScenicArea scenicArea)
    {
        List<ScenicArea> list = scenicAreaService.selectScenicAreaList(scenicArea);
        ExcelUtil<ScenicArea> util = new ExcelUtil<ScenicArea>(ScenicArea.class);
        util.exportExcel(response, list, "景区信息数据");
    }

    /**
     * 获取景区信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('api:scenicArea:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scenicAreaService.selectScenicAreaById(id));
    }

    /**
     * 新增景区信息
     */
    @PreAuthorize("@ss.hasPermi('api:scenicArea:add')")
    @Log(title = "景区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScenicArea scenicArea)
    {
        return toAjax(scenicAreaService.insertScenicArea(scenicArea));
    }

    /**
     * 修改景区信息
     */
    @PreAuthorize("@ss.hasPermi('api:scenicArea:edit')")
    @Log(title = "景区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScenicArea scenicArea)
    {
        return toAjax(scenicAreaService.updateScenicArea(scenicArea));
    }

    /**
     * 删除景区信息
     */
    @PreAuthorize("@ss.hasPermi('api:scenicArea:remove')")
    @Log(title = "景区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scenicAreaService.deleteScenicAreaByIds(ids));
    }


    /**
     * 判断当前用户是否已购买当前景区视频权限
     */
//    @PreAuthorize("@ss.hasPermi('api:scenicArea:remove')")
//    @Log(title = "判断景区视频权限", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/checkPaid")
    public AjaxResult checkPaid(@RequestBody ApiUserScenicArea userScenicArea)
    {
        return success(userScenicAreaService.checkUserScenicLinkStatus(userScenicArea));
    }

}
